package com.codejiwei.flink.practice;

import org.apache.flink.streaming.api.datastream.KeyedStream;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

/**
 * @author jiwei
 * @description
 * @date 2023/5/19 17:31
 */
public class Flink_Transform_Aggregate {
    public static void main(String[] args) throws Exception {
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
        env.setParallelism(4);

        KeyedStream<Integer, String> keyedStream = env.fromElements(1, 2, 3, 4, 5)
                .keyBy(ele -> ele % 2 == 0 ? "偶数" : "奇数");

        keyedStream.sum(0).print("sum");
        keyedStream.max(0).print("max");
        keyedStream.min(0).print("min");

        env.execute();
    }
}
